package com.zboin.service;

import com.zboin.common.domain.AjaxResult;
import com.zboin.domain.UserInfo;
import com.zboin.utils.EncryptUtil;
import com.zboin.mapper.UserInfoMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author zhboom
 * @date 2025/6/10 22:36
 */
@Service
public class UserService {

    @Value("${zboin.password.salt}")
    private String salt;

    private final UserInfoMapper userInfoMapper;

    public UserService(UserInfoMapper userInfoMapper) {
        this.userInfoMapper = userInfoMapper;
    }

    public AjaxResult addUser(UserInfo userInfo) {
        userInfo.setRole("admin");
        String encrypted = EncryptUtil.encryptMd5(userInfo.getPassword(), salt);
        userInfo.setPassword(encrypted);
        int update = userInfoMapper.insert(userInfo);
        return AjaxResult.toAjaxResult(update);
    }
}
